package com.shelpe.services.sustainer.step;

import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.beans.factory.annotation.Autowired;

import com.shelpe.services.sustainer.entity.jpa.InprogressJob;
import com.shelpe.services.sustainer.repository.jpa.InprogressJobRepository;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InprogressCleanerStep extends AbstractStep {

	@Autowired
	private InprogressJobRepository inprogressJobRepository;
	
	@Override
	protected void doExecute(StepExecution stepExecution) throws Exception {
		InprogressJob job = this.inprogressJobRepository.findOne(stepExecution.getJobExecution().getJobId() + "");
		log.debug("delete {} inprogress job: {}", stepExecution.getJobExecution(), job);
		if(job != null){
			this.inprogressJobRepository.delete(job);
		}
	}

}
